package com.sishu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sishu.pojo.Game;
import com.sishu.pojo.VO.GameVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;


public interface GameMapper extends BaseMapper<Game> {


    @Select("SELECT MAX(id) FROM game")
    Integer selectMaxgameId();

    @Select("SELECT * FROM game WHERE end_time > #{time} and active = 1 ")
    List<Game> selectAll(@Param("time") LocalDateTime time);

    @Select("SELECT * FROM game WHERE #{time} between create_time and end_time and active = 1 ")
    List<Game> inittime(@Param("time") LocalDateTime time);

    @Select("SELECT * FROM game")
    List<Game> allgame();


    @Update("UPDATE game SET active = 0")
    void setactivezero();

    @Select("SELECT * FROM game WHERE game_id = #{gameId}")
    Game selectgame(@Param("gameId") String gameId);


    @Select("SELECT g.game_id,g.game_difficulty,g.create_time,g.end_time,gg.active,gus.group_id,gus.s_id,gus.isdelete,gus.upgrade_times," +
            "role.role_id,role.role_name,role.skill_name,role.level ,role.level_name,role.upgrade_condition,role.role_price " +
            "FROM game g LEFT JOIN  gamegroups gg on g.game_id = gg.game_id JOIN gus on gg.group_id = gus.group_id" +
            " JOIN role on role.role_id = gus.role_id where g.game_id = #{gameId} order by group_id,s_id")
    List<GameVo> selectgusroleandgamegroups(String gameId);

    @Select("SELECT * FROM game WHERE active = 1")
    Game seedifficulty();
}
